<template>
  <nav-bar>
    <div slot="left" class="back" @click="backClick">
      <img src="~assets/images/common/back.svg" alt="" />
    </div>
    <div slot="center" class="title">
      <div
        v-for="(item, index) in titles"
        class="childTit"
        :key="item"
        :class="{ active: index == currentIndex }"
        @click="detailClick(index)"
      >
        {{ item }}
      </div>
    </div>
  </nav-bar>
</template>

<script>
import NavBar from 'components/common/navbar/NavBar'

export default {
  name: 'DetailNavBar',
  data() {
    return {
      titles: ['商品', '参数', '评论', '推荐'],
      currentIndex: 0,
      path: null
    }
  },
  methods: {
    detailClick(i) {
      this.currentIndex = i
      this.$emit('titleClick', i)
    },
    backClick() {
      this.$router.back()
    }
  },
  components: {
    NavBar
  },
  mounted() {
    this.$bus.$on('path', path => {
      path ? (this.path = path) : '/home'
    })
  }
}
</script>

<style type="text/css" scoped>
.back {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
.title {
  display: flex;
}
.childTit {
  flex: 1;
}
.active {
  color: var(--color-high-text);
}
</style>
